// components/edit-mode-item/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    item:{
      type:Object
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
   
  },
  lifetimes:{
    attached(){
 
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    changeStrength(e){
      let strength = e.currentTarget.dataset.strength
      this.setData({
        item:{
          ...this.data.item,
          strength
        }
      })
    },
    changeChoushuiSec(e){
      let number = e.currentTarget.dataset.number
      let item = this.data.item
      if(item.choushui_sec <= 0.1 && Number(number) < 0){
        return
      }
      if(item.choushui_sec >= 2 && Number(number) > 0){
        return
      }
      this.setData({
        item:{
          ...item,
          choushui_sec:(item.choushui_sec += Number(number)).toFixed(1) - 0
        }
      })
    },
    changeSleepSec(e){
      let number = e.currentTarget.dataset.number
      let item = this.data.item
      if(item.sleep_sec <= 0.1 && Number(number) < 0){
        return
      }
      if(item.sleep_sec >= 2 && Number(number) > 0){
        return
      }
      this.setData({
        item:{
          ...item,
          sleep_sec:(item.sleep_sec += Number(number)).toFixed(1) - 0
        }
      })
    },
    cancel(){
      this.triggerEvent('itemcancel')
    },
    confirm(){
      this.triggerEvent('itemsave',{item:this.data.item})
    }
  },
  
})
